/*
 * Created using SharpDevelop.
 * User: Steve
 * Date: 14/11/2006
 * Time: 10:03 PM
 * 
 */

using System;
using System.Windows.Forms;
using Mokey.Common.UserInput.CodeProject;

namespace Mokey.ThunderCards.GlobalHotKeys
{
	/// <summary>
	/// Description of GlobalHotKeyController.
	/// </summary>
	public class GlobalHotKeyController
	{
		public GlobalHotKeyController()
		{
		}
		
		private SystemHotkey _stopCardShowHotKey;
		private SystemHotkey _startCardShowHotKey;
		private SystemHotkey _toggleCardQuestionHotKey;
		private SystemHotkey _toggleCardAnswerHotKey;
		private SystemHotkey _playCardSoundHotKey;
		private SystemHotkey _showPreviousCardHotKey;
		private SystemHotkey _showNextCardHotKey;
		
		private void RemoveHotKey(SystemHotkey hotKeyToRemove)
		{
			if (hotKeyToRemove != null)
			{
				hotKeyToRemove.Dispose();
			}
		}
		private void FireHotKeyPressedEvent(EventHandler eventToFire)
		{
			if (eventToFire != null)
			{
				eventToFire(this, new EventArgs());
			}
		}
		
		public void LoadHotKeys(GlobalHotKeySettings settings)
		{
			RemoveHotKey(_stopCardShowHotKey);
			RemoveHotKey(_startCardShowHotKey);
			RemoveHotKey(_toggleCardQuestionHotKey);
			RemoveHotKey(_toggleCardAnswerHotKey);
			RemoveHotKey(_playCardSoundHotKey);
			RemoveHotKey(_showPreviousCardHotKey);
			RemoveHotKey(_showNextCardHotKey);
			
			_stopCardShowHotKey = new SystemHotkey();
			_stopCardShowHotKey.Pressed += new EventHandler(StopCardShowHotKey_Pressed);
			_stopCardShowHotKey.Shortcut = settings.StopCardShowShortcut;
			
			_startCardShowHotKey = new SystemHotkey();
			_startCardShowHotKey.Pressed += new EventHandler(StartCardShowHotKey_Pressed);
			_startCardShowHotKey.Shortcut = settings.StartCardShowShortcut;
			
			_toggleCardQuestionHotKey = new SystemHotkey();
			_toggleCardQuestionHotKey.Pressed += new EventHandler(ToggleCardQuestionHotKey_Pressed);
			_toggleCardQuestionHotKey.Shortcut = settings.ToggleCardQuestionShortcut;
			
			_toggleCardAnswerHotKey = new SystemHotkey();
			_toggleCardAnswerHotKey.Pressed += new EventHandler(ToggleCardAnswerHotKey_Pressed);
			_toggleCardAnswerHotKey.Shortcut = settings.ToggleCardAnswerShortcut;
			
			_playCardSoundHotKey = new SystemHotkey();
			_playCardSoundHotKey.Pressed += new EventHandler(PlayCardSoundHotKey_Pressed);
			_playCardSoundHotKey.Shortcut = settings.PlayCardSoundShortcut;
			
			_showPreviousCardHotKey = new SystemHotkey();
			_showPreviousCardHotKey.Pressed += new EventHandler(ShowPreviousCardHotKey_Pressed);
			_showPreviousCardHotKey.Shortcut = settings.ShowPreviousCardShortcut;
			
			_showNextCardHotKey = new SystemHotkey();
			_showNextCardHotKey.Pressed += new EventHandler(ShowNextCardHotKey_Pressed);
			_showNextCardHotKey.Shortcut = settings.ShowNextCardShortcut;
		}
		
		public void StopCardShowHotKey_Pressed(object sender, EventArgs e)
		{
			FireHotKeyPressedEvent(StopCardShowPressed);
		}
		public void StartCardShowHotKey_Pressed(object sender, EventArgs e)
		{
			FireHotKeyPressedEvent(StartCardShowPressed);
		}
		public void ToggleCardQuestionHotKey_Pressed(object sender, EventArgs e)
		{
			FireHotKeyPressedEvent(ToggleCardQuestionPressed);
		}
		public void ToggleCardAnswerHotKey_Pressed(object sender, EventArgs e)
		{
			FireHotKeyPressedEvent(ToggleCardAnswerPressed);
		}
		public void PlayCardSoundHotKey_Pressed(object sender, EventArgs e)
		{
			FireHotKeyPressedEvent(PlayCardSoundPressed);
		}
		public void ShowPreviousCardHotKey_Pressed(object sender, EventArgs e)
		{
			FireHotKeyPressedEvent(ShowPreviousCardPressed);
		}
		public void ShowNextCardHotKey_Pressed(object sender, EventArgs e)
		{
			FireHotKeyPressedEvent(ShowNextCardPressed);
		}
		
		public event EventHandler StopCardShowPressed;
		public event EventHandler StartCardShowPressed;
		public event EventHandler ToggleCardQuestionPressed;
		public event EventHandler ToggleCardAnswerPressed;
		public event EventHandler PlayCardSoundPressed;
		public event EventHandler ShowPreviousCardPressed;
		public event EventHandler ShowNextCardPressed;
	}
}
